import sys  
from PyQt5.QtWidgets import QApplication

import start
import about
import chat
import result

import numpy as np 
import pandas as pd
import re
import string
from sklearn.model_selection import train_test_split
from xgboost import XGBClassifier
from sklearn.metrics import accuracy_score
import joblib
import warnings
from sklearn.feature_extraction.text import TfidfVectorizer
from translate import Translator
import webbrowser

if __name__ == '__main__':
    app = QApplication(sys.argv)  
    
    satartWin = start.startwindow()  
    satartWin.show() 
    app.exec_()
    
    chatWin = chat.ChatBot()  
    chatWin.show()
    app.exec_()

    r=chat.data

    tfidf=joblib.load('../model/modelsave/tfidf.pkl')
    EImodel=joblib.load('../model/modelsave/EImodel.pkl')
    SNmodel=joblib.load('../model/modelsave/SNmodel.pkl')
    TFmodel=joblib.load('../model/modelsave/TFmodel.pkl')
    JPmodel=joblib.load('../model/modelsave/JPmodel.pkl')

    translator= Translator(from_lang="ZH",to_lang="EN")
    x=translator.translate(r)
    ss=[]
    ss.append(x)
    ss = tfidf.transform(ss)
    y1=EImodel.predict(ss)
    y2=SNmodel.predict(ss)
    y3=TFmodel.predict(ss)
    y4=JPmodel.predict(ss)
    
    y=''
    if y1==1:
        y=y+'E'
    else:
        y=y+'I'
    
    if y2==1:
        y=y+'S'
    else:
        y=y+'N'
    
    if y3==1:
        y=y+'T'
    else:
        y=y+'F'
    
    if y4==1:
        y=y+'J'
    else:
        y=y+'P'


    resultWin = result.resultwindow(y)  
    resultWin.show()
    
if y=='ESTJ':
    webbrowser.open('file:///D:/collge/jqxx/newcode/web/ba.html')
elif y=='ENFJ':
    webbrowser.open('file:///D:/collge/jqxx/newcode/web/er.html')
elif y=='ESTP':
    webbrowser.open('file:///D:/collge/jqxx/newcode/web/jiu.html')
elif y=='ESFJ':
    webbrowser.open('file:///D:/collge/jqxx/newcode/web/liu.html')
elif y=='ESFP':
    webbrowser.open('file:///D:/collge/jqxx/newcode/web/qi.html')
elif y=='ENFP':
    webbrowser.open('file:///D:/collge/jqxx/newcode/web/san.html')
elif y=='INFJ':
    webbrowser.open('file:///D:/collge/jqxx/newcode/web/shi.html')
elif y=='INTJ':
    webbrowser.open('file:///D:/collge/jqxx/newcode/web/shier.html')
elif y=='ISTJ':
    webbrowser.open('file:///D:/collge/jqxx/newcode/web/shiliu.html')
elif y=='ISTP':
    webbrowser.open('file:///D:/collge/jqxx/newcode/web/shiqi.html')
elif y=='INTP':
    webbrowser.open('file:///D:/collge/jqxx/newcode/web/shisan.html')
elif y=='ISFJ':
    webbrowser.open('file:///D:/collge/jqxx/newcode/web/shisi.html')
elif y=='ISFP':
    webbrowser.open('file:///D:/collge/jqxx/newcode/web/shiwu.html')
elif y=='INFP':
    webbrowser.open('file:///D:/collge/jqxx/newcode/web/shiyi.html')
elif y=='ENTJ':
    webbrowser.open('file:///D:/collge/jqxx/newcode/web/si.html')
elif y=='ENTP':
    webbrowser.open('file:///D:/collge/jqxx/newcode/web/wu.html')

sys.exit(app.exec_())
